package cn.webrx.coll;/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Project: jse2204 - cn.webrx.coll.ArrayList3
 * <p>Powered by webrx On 2022-09-19 09:10:54
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class ArrayList3 {
    public static void main(String[] args) {

        //List<Integer> nums = List.of(1,2,3); 快速建立只读List
        //nums.add(40)
        //nums.clear();
        //System.out.println(nums.size());

        List<Double> ds = new ArrayList<>(List.of(1d, 2d, 3d, 1d, 2d, 3d, 4d));
        ds.add(4.5);
        ds.addAll(List.of(10d, 20d, 30d));
        //System.out.println(ds.contains(30d));

        //System.out.println(ds.containsAll(List.of(1d, 4.5, 20d, 100d)));

        //删除其它的数据
        //ds.retainAll(List.of(1d, 2d, 3d));

        //删除子集合数据
        //ds.removeAll(List.of(1d, 2d, 3d));

        System.out.println(ds);

        //方法一
        ds.replaceAll(a -> a >= 2 ? a * .5 : a);

        //方法二
        for (int i = 0; i < ds.size(); i++) {
            if (ds.get(i) >= 2) {
                ds.set(i, ds.get(i) * .5);
            }
        }


        System.out.println(ds);
    }
}
